package org.x.usermod.controller;

import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.x.commonmod.enums.LogAsync;
import org.x.commonmod.config.Result;
import org.x.usermod.dto.SysAclCreateDTO;
import org.x.usermod.dto.SysAclDTO;
import org.x.usermod.dto.SysAclListDTO;
import org.x.usermod.dto.SysAclUpdateDTO;
import org.x.usermod.service.ISysAclService;
import org.springframework.web.bind.annotation.RestController;


/**
 * 权限表 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/api/sysAcl")
public class SysAclController {

    @Autowired
    private ISysAclService sysAclService;

    /**
     * 添加 权限表
     *
     * @param sysAclCreateDTO 权限表
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/create")
    public Result create(@RequestBody @Valid SysAclCreateDTO sysAclCreateDTO) {
        return Result.ok(sysAclService.create(sysAclCreateDTO));
    }


    /**
     * 根据主键逻辑删除权限表
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
   public Result remove(@PathVariable Integer id) {
        return Result.ok(sysAclService.removeById(id));
   }

    /**
     * 根据主键更新权限表
     *
     * @param sysAclUpdateDTO 更新权限表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
   public Result update(@RequestBody @Valid SysAclUpdateDTO sysAclUpdateDTO) {
       return Result.ok(sysAclService.update(sysAclUpdateDTO));

    }


    /**
     * 分页查询所有权限表
     *
     * @return 所有数据
     */
    @LogAsync(value = "查询权限列表")
    @GetMapping("/pagelist")
    public Result pagelist(SysAclListDTO sysAclListDTO) {
        return Result.ok(sysAclService.pagelist(sysAclListDTO));
    }

    /**
     * 查询所有权限表
     *
     */
    @LogAsync(value = "查询权限列表")
    @GetMapping("/list")
    public Result list(SysAclDTO sysAclDTO) {
        return Result.ok(sysAclService.list(sysAclDTO));
    }



}